home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / other / hunk / rexx / patchfile.rexx < prev    next >
OS/2 REXX Batch file  |  1999-06-14  |  2KB  |  59 lines

  1. /* Patch a given binary by a given patch 
  2.    © 1998 THOR Software. */
  3.  
  4. PARSE ARG binary patch .
  5. if binary='?' | binary='' then; do
  6.     say 'Usage: PatchFile.rexx <binary> <patch>,'
  7.     say 'where <binary> is the FULL path of an object module'
  8.     say 'and <patch> is the name of a .hop file to apply.'
  9.     exit 0
  10. end
  11. if ~exists(binary) then; do
  12.     say 'I can'D2C(39)'t find the file "'binary'", please check!'
  13.     exit 10
  14. end
  15. if patch='' then;do
  16.     say 'A Patch file (.hop file) is required for the operation.'
  17.     exit 5
  18. end
  19. if ~show(P,'HUNK.1') then; do
  20.     if ~open(.hunklocation,'ENV:Hunk','R') then; do
  21.         address command 'RequestFile Drawer="SYS:" NoIcons Title="Please locate the Hunk" >ENV:Hunk'
  22.         if ~open(.hunklocation,'ENV:Hunk','R') then; exit
  23.         address command 'Copy ENV:Hunk to ENVARC:Hunk'
  24.     end    
  25.     wherehunk=readln(.hunklocation)
  26.     close(.hunklocation)
  27.     if wherehunk='' then; do
  28.         address command 'Delete >NIL: ENV:Hunk ENVARC:Hunk'
  29.         exit
  30.     end
  31.     wherehunk=substr(wherehunk,2,length(wherehunk)-2)
  32.     snip=max(lastpos(':', wherehunk),lastpos('/', wherehunk)) +1
  33.     filename=substr(wherehunk,snip)
  34.     pathname=strip(left(wherehunk, snip-1),'T', '/')
  35.     pragma('D',pathname)
  36.     address command 'run' filename
  37. end
  38. do i=1 while ~show(P,'HUNK.1') & (i<10)
  39.     address command 'Wait 1'
  40. end
  41. if i>9 then; do
  42.     say "Can't lauch the Hunk processor."
  43.     say "Delete ENV:Hunk, ENVARC:Hunk and try again."
  44.     exit
  45. end
  46. address 'HUNK.1'
  47. LOCKGUI
  48. VERIFY off
  49. OPEN binary
  50. ApplyPatch patch
  51. COUNT 'hunks'
  52. do i=0 to hunks-1
  53.     StripZeros i
  54. end
  55. SAVE binary
  56. VERIFY on
  57. UNLOCKGUI
  58. WINDOWTOBACK    
  59.